import axios from 'axios'
import {
	Message
} from 'element-ui'
// import {
// 	getStorage
// } from "@/utils/localStorage.js";
// import Router from '@/router'

const URL = "http://localhost:8081"
// const URL = "http://192.168.42.88:8081/"// lxy公网ip（勿动！）

// create an axios instance
const service = axios.create({
	baseURL: URL, // url = base url + request url
	timeout: 10000, // request timeout
	withCredentials: true,
	crossDomain: true
})

service.interceptors.response.use(
	response => {
		if (response.data) {
			console.log(response)
			// if (response.config.url.includes('delete')) {
			// if (response.config.url.includes('delete') || 
			// response.config.url.includes('Insert') || 
			// response.config.url.includes('edit')) {
			// 	return response.data
			// }
			//服务器返回了数据
			//对返回结果进行判断
			if (response.data.code == 200) {
				return response.data
			} else if (response.data.code == -2) {
				//登录失效，跳转回登录页面
				Message({
					message: response,
					type: "error",
					duration: 2000,

				});
				Router.push({
					path: "/"
				})
				return false;
			}
			return -1;
		}
	},
	error => {
		return Promise.reject(error)
	},
)


export default service
